#include "games/checkgame.h"

CheckGame::CheckGame(QWidget *parent, int difflvl) :
    BaseGame(parent, difflvl)
{
    n_rows = 10 + 2 * difficulty_level;
    n_cols = 10 + 2 * difficulty_level;

    map = new QCheckBox**[n_rows];
    for(int r = 0; r < n_rows; r++) {
        map[r] = new QCheckBox*[n_cols];

        for(int c = 0; c < n_cols; c++) {
            QCheckBox * p = new QCheckBox(this);
            map[r][c] = p;
            p->setChecked(true);
            if(r > 0) {
                this->connect(p, SIGNAL(clicked()), map[r-1][c], SLOT(toggle()));
                this->connect(map[r-1][c], SIGNAL(clicked()), p, SLOT(toggle()));
            }
            if(c > 0) {
                this->connect(p, SIGNAL(clicked()), map[r][c-1], SLOT(toggle()));
                this->connect(map[r][c-1], SIGNAL(clicked()), p, SLOT(toggle()));
            }
            lay->addWidget(p, r, c);
        }
    }
}

bool CheckGame::isSolved()
{
    for(int r = 0; r < n_rows; r++) {
        for(int c = 0; c < n_cols; c++) {
            if( map[r][c]->isChecked() ) return false;
        }
    }
    return true;
}
